package com.ef.web.action;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;

import com.ef.constant.ConfirmMessage;
import com.ef.domain.Complain;
import com.ef.service.ComplainService;
import com.ef.util.CustomExample;

public class ComplainAction extends BaseAction<Complain> {

	private static final long serialVersionUID = 1L;
	
	private ComplainService complainService;
	
	@SuppressWarnings("serial")
	public String list(){
		this.listResult = complainService.findByExample(new CustomExample<Complain>(
				this.getModel()) {

			public void appendCondition(Criteria criteria) {
				this.enableLike(MatchMode.ANYWHERE);
			}
		}, this.getStartIndex(), this.getPageSize());
		return LIST;
	}
	
	public String save(){
		Complain complain = this.getModel();
		complain.setUpdateTime(new Date());
		complain.setUpdateUser(getSessionUser());
		complainService.saveOrUpdate(complain);
		this.setResult(ConfirmMessage.Complain);
		return EDIT;
	}

	public String edit(){
		
		return EDIT;
	}
	
	public String delete(){
		String ids = getRequest().getParameter("ids");
		String[] id = ids.split(",");
		for (String i : id) {
			complainService.delete(complainService.findById(Long.valueOf(i)));
		}
		return DELETE;
	}

	public ComplainService getComplainService() {
		return complainService;
	}

	public void setComplainService(ComplainService complainService) {
		this.complainService = complainService;
	}
	
	
}
